<?php
namespace app\index\controller;
use app\index\model\User;
use think\Controller;
use think\Db;

class Index extends Controller
{
	/**
	 * 主页
	 */
    public function index()
    {
        return $this->fetch();
    }

	/**
	 * 签到方法
	 * @throws \think\Exception
	 * @throws \think\exception\DbException
	 */
    public function sign(){
		if(session('uid')){
			$user = User::get(session('uid'));
			$sign_time = $user->sign_time;
				if ($user && time()-$sign_time>=86400){
					$res = User::where('uid', $user->uid)
						->update(['sign_time' => time()]);
					if ($res){
						Db::name('user')->where('uid', $user->uid)->setInc('integral', 5);
						$this->success('签到成功');
					}
				}else{
					$this->error('你今天已经签到了，请明天再来');
				}
		}else{
			$this->error('请先登陆');
		}
	}
}
